//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using System.ComponentModel;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation;
using EntLibContrib.Common.Configuration.Design;
using EntLibContrib.Query.Properties;

namespace EntLibContrib.Query.Configuration.Design
{
  /// <summary>
	/// Represents a <see cref="ParameterSetData"/> configuration element. This class is abstract.
  /// </summary>
  [Image(typeof(ParameterSetNode))]
  [SelectedImage(typeof(ParameterSetNode))]
  public class ParameterSetNode : NameSortConfigurationNode
	{
		#region Properties
		/// <summary>
		/// Gets the name of the node.
		/// </summary>
		/// <value>The name of the node.</value>
		[UniqueName(typeof(ParameterSetNode), typeof(QuerySettingsNode))]
		public override string Name
		{
			get { return base.Name; }
		}

		/// <summary>
		/// Gets the <see cref="ParameterSetData"/> this node represents.
		/// </summary>
		/// <value>
		/// The <see cref="ParameterSetData"/> this node represents.
		/// </value>
		[Browsable(false)]
		public ParameterSetData ParameterSetData
		{
			get { return new ParameterSetData(Name); }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="ParameterSetNode"/> class.
		/// </summary>
		public ParameterSetNode()
			: this(new ParameterSetData(InternalResources.DefaultParameterSetNodeName))
    {
		}

		/// <summary>
		/// Initialize a new instance of the <see cref="ParameterSetNode"/> class with an <see cref="ParameterSetData"/> instance.
		/// </summary>
		/// <param name="parameterSetData">An <see cref="ParameterSetData"/> instance</param>
		public ParameterSetNode(ParameterSetData parameterSetData)
    {
			if (parameterSetData == null)
      {
				throw new ArgumentNullException("parameterSetData");
      }

			Rename(parameterSetData.Name);
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Clones this instance.
		/// </summary>
		/// <returns></returns>
		public ParameterSetNode Clone()
		{
			ParameterSetNode parameterSetNode = new ParameterSetNode(this.ParameterSetData);
			foreach (ConfigurationNode parameterNode in this.Nodes)
			{
				ParameterNode node = parameterNode as ParameterNode;
				if (node != null)
				{
					ParameterNode newParameterNode = node.Clone();
					parameterSetNode.AddNode(newParameterNode);
				}
			}
			return parameterSetNode;
		}
		#endregion
	}
}